/**
 * Created by LeungZ on 2016/9/8.
 */
import './image.scss';

import temp from './image.html';
import ctrl from './image.ctrl.js';

import dtlTemp from './detail/detail.html';
import dtlCtrl from './detail/detail.ctrl.js';

export default angular.module('ctg-k8sconsole').config(['$stateProvider', $stateProvider=> {
    $stateProvider.state('docker-image', {
        url: '/docker/image',
        templateUrl: temp,
        controller: ctrl,
        controllerAs: 'list',
        resolve: {
            list: ['imageSrv', 'ctgNotification', function (imageSrv, ctgNotification) {
                return imageSrv.getImageList({currentPage: 1}).catch(function (data) {
                    ctgNotification.error('获取Docker镜像列表数据有误.');
                });
            }]
        }
    }).state('docker-image-detail', {
        url: '/docker/image/:imageId',
        templateUrl: dtlTemp,
        controller: dtlCtrl,
        controllerAs: 'dtl',
        resolve: {
            detail: ['imageSrv', 'ctgNotification', '$stateParams', function (imageSrv, ctgNotification, $stateParams) {
                return imageSrv.getImageDetail({id: $stateParams.imageId}).catch(function (data) {
                    ctgNotification.error('获取Docker镜像详情数据有误.');
                });
            }],
            verList: ['imageSrv', 'ctgNotification', '$stateParams', function (imageSrv, ctgNotification, $stateParams) {
                return imageSrv.getImageVers({id: $stateParams.imageId, currentPage: 1}).catch(function (data) {
                    ctgNotification.error('获取Docker镜像版本列表数据有误.');
                });
            }]
        }
    })
}]);